package top.loonglove.common.base.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.loonglove.common.base.dao.BaseDao;
import top.loonglove.common.base.entity.BaseEntity;
import top.loonglove.common.base.query.BasePageQuery;
import top.loonglove.common.base.query.BaseQuery;
import top.loonglove.common.base.result.PageResult;
import top.loonglove.common.base.service.BaseService;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2021/7/28 2:56
 */
@Service
public class BaseServiceImpl implements BaseService<BaseEntity, BaseQuery,BasePageQuery> {
    private final BaseDao<BaseEntity,BaseQuery,BasePageQuery> dao;

    @Autowired
    public BaseServiceImpl(BaseDao<BaseEntity,BaseQuery,BasePageQuery> dao) {
        this.dao = dao;
    }

    /**
     * 添加数据
     *
     * @param baseEntity 数据
     */
    @Override
    public void add(BaseEntity baseEntity) {
        dao.add(baseEntity);
    }

    /**
     * 删除数据，假删除
     *
     * @param baseEntity 数据
     */
    @Override
    public void remove(BaseEntity baseEntity) {
        dao.remove(baseEntity);
    }

    /**
     * 获取数据
     *
     * @param baseQuery 查询项
     * @return 数据
     */
    @Override
    public BaseEntity get(BaseQuery baseQuery) {
        return dao.get(baseQuery);
    }

    /**
     * 分页获取查询项
     *
     * @param baseQuery extend BasePageQuery
     * @return 分页查询结果
     */
    @Override
    public PageResult<BaseEntity> getPage(BasePageQuery baseQuery) {
        return dao.getPage(baseQuery);
    }

    /**
     * 修改数据
     *
     * @param baseEntity 新数据
     */
    @Override
    public void modify(BaseEntity baseEntity) {
        dao.modify(baseEntity);
    }

    /**
     * 删除数据，真删除
     *
     * @param baseEntity 删除数据
     */
    @Override
    public void delete(BaseEntity baseEntity) {
        dao.delete(baseEntity);
    }
}
